fix(spend): remove duplicate _common_add_spend_log_transaction call in agent spend path#21288
fix(spend): remove duplicate _common_add_spend_log_transaction call in agent spend path#21288ArivunidhiA wants to merge 1 commit intoBerriAI:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR removes a redundant duplicate call to
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/db/db_spend_update_writer.py | Removed 13 lines of redundant code: the duplicate _common_add_spend_log_transaction_to_daily_transaction call and the unnecessary payload_with_agent_id construction. The method now follows the same single-call pattern used by team, user, and tag variants. |
| tests/test_litellm/proxy/db/test_db_spend_update_writer.py | Added regression test for #21181 verifying _common_add_spend_log_transaction_to_daily_transaction is called exactly once in the agent spend path. Test uses mocks only (no network calls), following the project's test conventions. |
Sequence Diagram
sequenceDiagram
participant Caller as Spend Logger
participant Agent as add_spend_log_transaction_to_daily_agent_transaction
participant Common as _common_add_spend_log_transaction_to_daily_transaction
participant Queue as daily_agent_spend_update_queue
Note over Agent: Before Fix (2 calls)
Caller->>Agent: payload (with agent_id)
Agent->>Common: payload, "agent" (1st call)
Common-->>Agent: base_daily_transaction
Agent->>Agent: construct payload_with_agent_id (redundant copy)
Agent->>Common: payload_with_agent_id, "agent" (2nd call - DUPLICATE)
Common-->>Agent: base_daily_transaction (same result)
Agent->>Queue: add_update(daily_transaction)
Note over Agent: After Fix (1 call)
Caller->>Agent: payload (with agent_id)
Agent->>Common: payload, "agent" (single call)
Common-->>Agent: base_daily_transaction
Agent->>Queue: add_update(daily_transaction)
Last reviewed commit: 87ba840
…n agent spend path
87ba840 to
62b7fdb
Compare
|
The 6 failing "LiteLLM Unit Tests (Matrix)" checks (integrations, llms, proxy-guardrails, proxy-unit-a, proxy-unit-b, root) are pre-existing failures that affect all fork PRs due to missing repo secrets. These same tests fail on unrelated docs-only PRs (e.g., #21283, #21282). All checks that can run on fork PRs pass successfully. |
|
Fixed with #21187 |
Fixes #21181
add_spend_log_transaction_to_daily_agent_transaction()calls_common_add_spend_log_transaction_to_daily_transaction()twice for the same request whenagent_idis present. The second call usespayload_with_agent_id, which is just{**payload, "agent_id": payload["agent_id"]}— identical topayloadsinceagent_idis already present. This duplicates JSON metadata parsing and status computation work on every agent spend log.Fix: Remove the redundant second call and the unnecessary
payload_with_agent_idconstruction. Reusebase_daily_transactionfrom the first call, matching the pattern already used by theteam,user,org, andend_uservariants of this function.Changed files:
litellm/proxy/db/db_spend_update_writer.py— removed 13 lines of redundant codetests/test_litellm/proxy/db/test_db_spend_update_writer.py— added regression test verifying the common helper is called exactly once